<script type="text/javascript">
$(function(){
	var pg = App.soagov.svcEdit.ui, pp = pg.params || {};
	
	var frm = {
		code: pg.seek('code'),
		name: pg.seek('name'),
		memo: pg.seek('memo')
	};

	function getValues(){
		return {
			id: pp.id,
			code: frm.code.val(),
			name: frm.name.val(),
			memo: frm.memo.val()
		};
	}
	function setValues(o){
		pg.seek('title').html(o.id? '编辑服务':'添加服务');
		frm.code.val(o.code);
		frm.name.val(o.name);
		frm.memo.val(o.memo);
	}
	function validate(p){
		var x2 = App.validate2, v = App.soagov.validation,
			m = pg.find('.msg').html('');
		return !x2(v.svc.code, frm.code)
			& !x2(v.svc.name, frm.name);
	}
	pg.find('input').blur(function(){
		var p = getValues();
 		validate(p);
	});
	pg.seek('ok').click(function(){
		var pms = getValues();
		if (!validate(pms)) {
			return;
		}
		mac.alert('Online demo do not allow this action');
		return false;
		//
		$.post(App.ctx + '/svc/save.do', pms, function(rs){
			var ro = mac.eval(rs);
			if (ro.success) {
				pg.callback(ro.data);//更新树	
				if (pg.close) {
					pg.close();
				}
			} else {
				pg.seek('msg').html(mac.msg(ro.data, ro.params));
			}
		});
		return false;
	});

	setValues(pp);
});
</script>
<div class="title" name="title">编辑服务</div>
<div class="form">
	<div class="item">
		<span class="label">英文名</span>
		<input type="text" name="code" maxlength="32" />
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">中文名</span>
		<input type="text" name="name" maxlength="32" />
		<span class="msg">*</span>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">描述</span>
		<textarea name="memo"></textarea>
		<div class="clear"></div>
	</div>
	<div class="item">
		<span class="label">&nbsp;</span>
		<div name="msg"></div>
		<div class="clear"></div>
	</div>
	<div class="bottom">
		<button name="ok">保存</button>
	</div>
</div>